﻿using UnityEngine;

public class LanguageCommand : Singleton<LanguageCommand>
{
    private LanguageCommand() { }
    public string GetTranslation(string key)
    {
        var scriptableObject = ProxyResourceFactory.Instance.Factory.GetScriptableObject<LanguageScriptableObject>();
        if (scriptableObject == null)
        {
            Debug.LogError("LanguageScriptableObject 為 null");
            return key;
        }
        
        if (scriptableObject.languageDatas == null)
        {
            Debug.LogError("languageDatas 為 null");
            return key;
        }
        
        Debug.Log($"languageDatas 數量: {scriptableObject.languageDatas.Count}");
        
        foreach (LanguageModel model in scriptableObject.languageDatas)
        {
            if (model.strList[0].CompareTo(key) == 0)
            {
                if (ArchiveQuery.Instance.GetLanguage() == LanguageType.English)
                {
                    return model.strList[0];
                }
                else
                {
                    return model.strList[1];
                }
            }
        }
        Debug.Log("LanguageCommand GetLanguage return null");
        return key;
    }
}
